﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Data.OleDb;
using System.Text;

public partial class Consulta_Cursos_Unidade : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            #region OldCode
            //wsMira.wsMira api = new wsMira.wsMira();
            //DataSet dsTurmas = api.pesquisaDadosDeTurmasParaPublicarNaInternet();//Ano(short.Parse(DateTime.Today.Year.ToString()));
            //DataView dvTurmas = new DataView(dsTurmas.Tables[0]);
            //dvTurmas.RowFilter = "Situacao='Liberada para Matricula' AND CODIGOUO=" + Request.QueryString["codunidope"].ToString() + " AND Pronatec = 'Não' And PSG = 'Não'";
            //dvTurmas.Sort = "Turma";
            //GridView1.DataSource = dvTurmas;
            //GridView1.DataBind();
            #endregion

            DataSet dsTurmas = new DataSet();
            SqlConnection conn = new SqlConnection("Data Source=10.9.8.9;Password=usr674532#5;User ID=intrausuario;Initial Catalog=Intranet");

            try
            {
                string sql = "SELECT *, CAST(turma as VARCHAR) as Turma " +
                               "FROM PSGDadosDeTurmasParaPublicarNaInternet " +
                              "WHERE Situacao LIKE 'Liberada para Matricula' AND CODIGOUO = " + Request.QueryString["codunidope"].ToString() + " AND Pronatec = 'Não' And PSG = 'Não' " +
                              "ORDER BY Turma";

                SqlCommand command = new SqlCommand(sql, conn);
                SqlDataAdapter adapter = new SqlDataAdapter(command);
                adapter.Fill(dsTurmas);
                
                DataView dvTurmas = new DataView(dsTurmas.Tables[0]);
                GridView1.DataSource = dvTurmas;
                GridView1.DataBind();
            }
            catch
            {
                throw;
            }
            finally
            {
                conn.Close();
            }
        }
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            DateTime dataInicio = DateTime.Parse(e.Row.Cells[1].Text);
            if (dataInicio < DateTime.Today)
                e.Row.Visible = false;
        }
    }
}
